package com.computer.spring.framework.aop.aspect;

import com.computer.spring.framework.aop.advice.BYAdvice;
import com.computer.spring.framework.aop.intercept.BYMethodInterceptor;
import com.computer.spring.framework.aop.intercept.BYMethodInvocation;

import java.lang.reflect.Method;

/**
 * @Description
 * @Author MagicIce
 * @Date 2020/11/23 8:36
 */
public class BYMethodBeforeAdvice extends BYAbstractAspectJAdvice implements BYAdvice, BYMethodInterceptor {

    private BYJoinPoint joinPoint;

    public BYMethodBeforeAdvice(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    public void before(Method method, Object[] args, Object target) throws Throwable{
        invokeAdviceMethod(this.joinPoint, null, null);
    }

    @Override
    public Object invoke(BYMethodInvocation methodInvocation) throws Throwable {
        this.joinPoint = methodInvocation;
        this.before(methodInvocation.getMethod(), methodInvocation.getArguments(), methodInvocation.getThis());
        return methodInvocation.proceed();
    }
}
